import { defineStore } from "pinia";
import { ref } from 'vue'
import { userGetInfoService } from '@/api/user'

// 用户登陆退出的token
export const useUserStore = defineStore('user', () => {
  const token = ref('')
  // 设置token
  const setToken = (newToken) => {
    token.value = newToken
  }
  //重置token
  const removeToken = () => {
    token.value = ''
  }
  // 获取用户基本信息
  const user = ref({})
  const getUser = async () => {
    const { data } = await userGetInfoService()
    user.value = data.data
  }
  const setUser = (obj) => {
    user.value = obj
  }
  return{
    token,
    setToken,
    removeToken,
    user,
    getUser,
    setUser
  }
},
{
  persist: true
})
